package com.example.house_manager;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class BottomMenuActivity extends TabActivity implements OnCheckedChangeListener {

private TabHost mTabHost;
private Intent mHomeIntent;
private Intent mSearchIntent;
private Intent mHouseIntent;
private Intent mMoreIntent;

protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_home);
this.mHomeIntent = new Intent(this, HomeActivity.class);
this.mSearchIntent = new Intent(this, SearchActivity.class);
this.mHouseIntent = new Intent(this, HouseActivity.class);
this.mMoreIntent = new Intent(this, MyHouseActivity.class);

((RadioButton) findViewById(R.id.radio_button00))
		.setOnCheckedChangeListener(this);
((RadioButton) findViewById(R.id.radio_button01))
		.setOnCheckedChangeListener(this);
((RadioButton) findViewById(R.id.radio_button02))
		.setOnCheckedChangeListener(this);
((RadioButton) findViewById(R.id.radio_button03))
		.setOnCheckedChangeListener(this);

setupIntent();
}

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
	switch (buttonView.getId()) {
	case R.id.radio_button00:
		this.mTabHost.setCurrentTabByTag("Home_TAB");
		break;
	case R.id.radio_button01:
		this.mTabHost.setCurrentTabByTag("Search_TAB");
		break;
	case R.id.radio_button02:
		this.mTabHost.setCurrentTabByTag("House_TAB");
		break;
	case R.id.radio_button03:
		this.mTabHost.setCurrentTabByTag("More_TAB");
		break;
	}
}

}

private void setupIntent() {
this.mTabHost = getTabHost();
TabHost localTabHost = this.mTabHost;

localTabHost.addTab(buildTabSpec("Home_TAB", R.string.home,
		R.drawable.home, this.mHomeIntent));

localTabHost.addTab(buildTabSpec("Search_TAB", R.string.search,
		R.drawable.search, this.mSearchIntent));

localTabHost.addTab(buildTabSpec("House_TAB", R.string.house,
		R.drawable.home, this.mHouseIntent));

localTabHost.addTab(buildTabSpec("More_TAB", R.string.myHouse,
		R.drawable.more, this.mMoreIntent));

}

private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
	final Intent content) {
return this.mTabHost
		.newTabSpec(tag)
		.setIndicator(getString(resLabel),
				getResources().getDrawable(resIcon))
		.setContent(content);
}

}
